import keyboard
import time

# 监听按键并执行操作
def on_key_event(event):
    if event.event_type == keyboard.KEY_DOWN:
        print(event.name, "key pressed at:", round(time.time()))
        # keyboard.write('Hello, world!')  # 当空格键被按下时，写入文本
        # keyboard.send('enter')  # 发送回车键

keyboard.hook(on_key_event)  # 安装钩子监听键盘事件
keyboard.wait('esc')  # 等待按下Esc键退出程序
